package com.xyh;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
@DefaultProperties()
public class MemberService {
    @Autowired
    private RestTemplate restTemplate;
    @HystrixCommand(fallbackMethod = "getMemberFallback",groupKey = "MemberGroup",commandKey = "MemberCommandKey",commandProperties={
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="1000")
    },threadPoolProperties = {
            @HystrixProperty(name="coreSize",value="2")
    })
    public Member getMember(Integer id){
        try{
            Thread.sleep(800);
        }catch (Exception e){

        }
      Member member=restTemplate.getForObject("http://spring-hy-member/member/{id}",Member.class,id);
      return member;
    }

    public Member getMemberFallback(Integer id){
        Member m=new Member();
        m.setId(id);
        m.setName("error member");
        return m;
    }
    @HystrixCommand()
   public Member cacheMember(Integer id){
       Member member= restTemplate.getForObject("http://spring-hy-member/member/{id}",Member.class,id);
       return member;
   }

}
